/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.SchoolManagerSystem;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.TextView;

/**
 * A @{code ImageView} which can rotate it's content.
 */
public class OnlineCoursePage
{
    @SuppressWarnings("unused")
    private static final String TAG = "OnlineCourseView";

	private final Context mContext;
    private View mMainPanel;
    
    private ListView mListView = null;
    private ListViewAdapter mMainAdapter;
    private final LayoutInflater mInflater;
    
    private List<String> mCourseNameList;
    private List<String> chooseditem;
    
    public OnlineCoursePage(
    		Context context, 
    		View mainPanel) 
    {
    	mContext = context;
    	mMainPanel = mainPanel;
    	
    	mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	mListView = (ListView)mMainPanel.findViewById(R.id.onlinecourse_coursemenu);
    }
    
    public void resetOnlineCourseList(List<String> courseNameList)
    {
    	mCourseNameList = courseNameList;
        mMainAdapter = new ListViewAdapter(mContext);
        mListView.setAdapter(mMainAdapter);
        mListView.setOnItemClickListener(new listViewClicker());
    }
    
    public List<String> getChooseitems()
    {
    	List<String> chooseditem = new ArrayList<String>();
    	return chooseditem;
    }

    private class listViewClicker implements OnItemClickListener 
    {	
    	public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    	{
    		Log.i(TAG, "listViewClicker position : " + Integer.toString(position));
			
    		CheckBox checkButton = (CheckBox) view.findViewById(R.id.onlinecourse_checkbtn);
   	
    		boolean bChecked = checkButton.isChecked();
			bChecked = !bChecked;
			checkButton.setChecked(bChecked);
    	}
    }
    
    private View inflateIfNeed(
            View view, int resource, ViewGroup root, 
            boolean attachToRoot) 
	{
        if (view != null) 
        {
        	return view;
        }
        
        return mInflater.inflate(resource, root, attachToRoot);
    }
    
    private class ListViewAdapter extends BaseAdapter
    	implements OnItemClickListener 
    {
    	public ListViewAdapter(Context context) 
    	{
    	}
    		
    	public View getView(
    			int position, 
    			View convertView, 
    			ViewGroup parent) 
    	{
    		convertView = inflateIfNeed(
    				convertView,
    				R.layout.onlinecourse_listitem, 
    				parent, 
    				false);
    		
    		TextView courseName = (TextView)convertView.findViewById(R.id.onlinecourse_coursename);
    		courseName.setText(mCourseNameList.get(position));
    		
    		return convertView;
    	}

		@Override
		public int getCount() 
		{
			// TODO Auto-generated method stub
			return mCourseNameList.size();
		}

		@Override
		public Object getItem(int arg0) 
		{
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) 
		{
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			// TODO Auto-generated method stub
			
		}
    }
}

